home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------
- // ImageOpen.cs ⌐ 2001 by Charles Petzold
- //----------------------------------------
- using System;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
-
- class ImageOpen: Form
- {
- protected string strProgName;
- protected string strFileName;
- protected Image image;
-
- public static void Main()
- {
- Application.Run(new ImageOpen());
- }
- public ImageOpen()
- {
- Text = strProgName = "Abrir imagen";
- ResizeRedraw = true;
-
- Menu = new MainMenu();
- Menu.MenuItems.Add("&Archivo");
- Menu.MenuItems[0].MenuItems.Add(new MenuItem("&Abrir...",
- new EventHandler(MenuFileOpenOnClick),
- Shortcut.CtrlO));
- }
- void MenuFileOpenOnClick(object obj, EventArgs ea)
- {
- OpenFileDialog dlg = new OpenFileDialog();
-
- dlg.InitialDirectory = "c:\\" ;
-
- dlg.Filter = "Todos los archivos de imßgenes|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;" +
- "*.jfif;*.png;*.tif;*.tiff;*.wmf;*.emf|" +
- "Mapa de bits de Windows (*.bmp)|*.bmp|" +
- "Icono de Windows (*.ico)|*.ico|" +
- "Formato de intercambio de grßficos (*.gif)|*.gif|" +
- "Formato de intercambio de archivos JPEG (*.jpg)|" +
- "*.jpg;*.jpeg;*.jfif|" +
- "Grßficos de red portables (*.png)|*.png|" +
- "Formato de archivo de marcas de imßgenes (*.tif)|*.tif;*.tiff|" +
- "Metarchivo de Windows (*.wmf)|*.wmf|" +
- "Metarchivo mejorado (*.emf)|*.emf|" +
- "Todos los archivos (*.*)|*.*";
-
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- try
- {
- image = Image.FromFile(dlg.FileName);
- }
- catch (Exception exc)
- {
- MessageBox.Show(exc.Message, strProgName);
- return;
- }
- strFileName = dlg.FileName;
- Text = strProgName + " - " + Path.GetFileName(strFileName);
- Invalidate();
- }
- }
- protected override void OnPaint(PaintEventArgs pea)
- {
- Graphics grfx = pea.Graphics;
-
- if (image != null)
- grfx.DrawImage(image, 0, 0);
- }
- }